﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using WickedSick.ClientComponents.Music;

namespace SDB
{
    public class MediaValueConverter : IMultiValueConverter, IValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter == null)
                return values[0].ToString();

            if (parameter.ToString() == "TrackNumberTitle")
            {
                return string.Format("{0}. {1}", values[0], values[1]);
            }
            else if (parameter.ToString() == "PlaylistSongTitle")
            {
                return string.Format("{0} - {1}", values[0], values[1]);
            }
            return values[0].ToString();
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (parameter.ToString() == "ReleaseDate")
            {
                return ((DateTime)value).ToShortDateString();
            }
            else if (parameter.ToString() == "AlbumSongCount")
            {
                if (((int)value) == 1)
                    return string.Format("{0} song", value);
                else
                    return string.Format("{0} songs", value);
            }
            else if (parameter.ToString() == "SizeInMb")
            {
                double dvalue = (double)value;
                if (dvalue >= 4096.0d)
                {
                    return "Unlimited";
                }
                else if (dvalue >= 1024.0d)
                {
                    dvalue = dvalue / 1024.0d;
                    dvalue = Math.Round(dvalue, 1);
                    return string.Format("{0} Gb", dvalue);
                }
                else if (dvalue <= 0.0d)
                {
                    return "Do not save locally";
                }
                else
                {
                    dvalue = Math.Round(dvalue, 0);
                    return string.Format("{0} Mb", dvalue);
                }
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
